<?php
/**
 * Created by PhpStorm.
 * User: Victor
 * Date: 2018/7/18
 * Time: 19:39
 */

namespace app\index\controller;

use app\common\redis\RedisPackage;
use think\Controller;
use think\Db;
use think\Request;
use think\cache\driver\Redis;

class Rizhi extends Controller
{
    public $redis;

    public function __construct()
    {
//        $redisConfig = config('redis');
//        $this->redis = new Redis($redisConfig);
    }

    public function index($user_id,$operation_category,$detail_name,$operation_value,$re_name,$re_value)
    {
        $arr = array();
        $result = array();
        $arr['user_id'] = $user_id;
        $arr['user_category'] = 2;
        $request = Request::instance();
        $ip = $request->ip();
        $arr['ip'] = $ip;
        $arr['operation_category'] = $operation_category;
        $arr['operation_time'] = time();
        $records = Db::name('operation_records')
                    ->insertGetId($arr);
        if($records>0){
            $array = array();
            for($x=0;$x<count($detail_name);$x++)
            {
                $array[$x]['detail_name'] = $detail_name[$x];
                $array[$x]['operation_value'] = $operation_value[$x];
                $array[$x]['par_id'] = $records;
            }
            $detail = Db::name('operation_records_detail')->insertAll($array);
            if ($detail>0){
                $re_name = 'update_bz';
                RedisPackage::getInstance();
                RedisPackage::set($re_name,$re_value);
                $result['code'] = 1;
                $result['msg'] = '已记录此次操作';
                return $result;
            }else{
                $result['code'] = 0;
                $result['msg'] = '写入日志详情表失败!';
                return $result;
            }
        }else{
            $result['code'] = 0;
            $result['msg'] = '写入日志表失败!';
            return $result;
        }
    }
    public function redis($yh_id,$hb_id)
    {

        $Redis= $this->redis;
        $arr = '4;'.$yh_id.';2;'.$hb_id.';2;';
        $Redis->rpush("task_list",$arr);
    }
}